home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / EDITSDI.PAK / PRINTDLG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  137 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: printdlg.c
  9. //
  10. //  PURPOSE:
  11. //    To show the use of the "Print" and "Print Setup" common dialog
  12. //    boxes.
  13. //
  14. //  FUNCTIONS:
  15. //    CmdPrint - Present the print dialog to the user and process the results.
  16. //    CmdPrintSU -Present the print setup common dialog to the user.
  17. //
  18. //  COMMENTS:
  19. //
  20. //
  21. //
  22. //  SPECIAL INSTRUCTIONS: N/A
  23. //
  24.  
  25. #include <windows.h>            // required for all Windows applications
  26. #ifdef WIN16
  27. #include <commdlg.h>
  28. #include "win16ext.h"           // required only for win16 applications
  29. #endif
  30. #include "globals.h"            // prototypes specific to this application
  31.  
  32. static HANDLE hDevMode = NULL;
  33. static HANDLE hDevNames = NULL;
  34.  
  35. //
  36. //  FUNCTION: CmdPrint(HWND, WORD, WORD, HWND)
  37. //
  38. //  PURPOSE: Present the print dialog to the user and process the results.
  39. //
  40. //  PARAMETERS:
  41. //    hwnd     - The window handle.
  42. //    wCommand - IDM_PRINT (Unused)
  43. //    wNotify  - Notification number (unused)
  44. //    hwndCtrl - NULL (Unused)
  45. //
  46. //  RETURN VALUE:
  47. //    Always returns 0 - Command handled.
  48. //
  49. //  COMMENTS:
  50. //
  51. //
  52.  
  53. #pragma argsused
  54. LRESULT CmdPrint(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl) {
  55.     PRINTDLG pd = {0};
  56.  
  57.     static DWORD Flags     = PD_ALLPAGES | PD_SHOWHELP | PD_RETURNDC;
  58.     static WORD  nFromPage = 0xFFFF;
  59.     static WORD  nToPage   = 0xFFFF;
  60.     static WORD  nCopies   = 1;
  61.  
  62.     DWORD  nPageRange = GetPageRange();
  63.  
  64.     pd.lStructSize = sizeof(pd);
  65.     pd.hwndOwner   = hwnd;
  66.     pd.hDevMode    = hDevMode;
  67.     pd.hDevNames   = hDevNames;
  68.     pd.Flags       = Flags;
  69.     pd.nFromPage   = nFromPage;
  70.     pd.nToPage     = nToPage;
  71.     pd.nMinPage    = LOWORD(nPageRange);
  72.     pd.nMaxPage    = HIWORD(nPageRange);
  73.     pd.nCopies     = nCopies;
  74.  
  75.     if (PrintDlg(&pd)) {
  76.         Print(
  77.             hwnd,
  78.             pd.hDC,
  79.             MAKEBOOL(pd.Flags & PD_PAGENUMS),
  80.             MAKEBOOL(pd.Flags & PD_SELECTION),
  81.             MAKEBOOL(pd.Flags & PD_COLLATE),
  82.             MAKEBOOL(pd.Flags & PD_PRINTTOFILE),
  83.             pd.nFromPage,
  84.             pd.nToPage,
  85.             pd.nCopies,
  86.             pd.hDevNames
  87.         );
  88.         hDevMode    = pd.hDevMode;
  89.         hDevNames   = pd.hDevNames;
  90.         Flags       = pd.Flags;
  91.         nFromPage   = pd.nFromPage;
  92.         nToPage     = pd.nToPage;
  93.     }
  94.     else {
  95.         CommDlgExtendedError();
  96.     }
  97.  
  98.     return 0;
  99. }
  100.  
  101.  
  102. //
  103. //  FUNCTION: CmdPrintSU(HWND, WORD, WORD, HWND)
  104. //
  105. //  PURPOSE: Present the print setup common dialog to the user.
  106. //
  107. //  PARAMETERS:
  108. //    hwnd     - The window handle.
  109. //    wCommand - IDM_PRINTSU (Unused)
  110. //    wNotify   - Notification number (unused)
  111. //    hwndCtrl - NULL (Unused)
  112. //
  113. //  RETURN VALUE:
  114. //    Always returns 0 - Command handled.
  115. //
  116. //  COMMENTS:
  117. //
  118. //
  119.  
  120. #pragma argsused
  121. LRESULT CmdPrintSU(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl) {
  122.      PRINTDLG pd = {0};
  123.  
  124.     pd.lStructSize = sizeof(pd);
  125.     pd.hwndOwner   = hwnd;
  126.     pd.hDevMode    = hDevMode;
  127.     pd.hDevNames   = hDevNames;
  128.     pd.Flags = PD_SHOWHELP | PD_PRINTSETUP;
  129.  
  130.     if (PrintDlg(&pd)) {
  131.         hDevMode = pd.hDevMode;
  132.         hDevNames = pd.hDevNames;
  133.     }
  134.  
  135.      return 0;
  136. }
  137.